#include <ximera/audio/openal/audiosystem.hpp>
#include <ximera/audio/openal/world.hpp>

namespace ximera { namespace audio { namespace openal
{
    AudioSystem::AudioSystem()
    {
        if (!alutInit(0, 0))
            checkErrorAndThrow(L"Failed to initialize ALUT");

        // Clear the error state        
        alGetError();
        alutGetError();

        ALfloat posvel[] = {0,0,0};
        ALfloat ori[] = {0,0,-1, 0,1,0};

        alListenerfv(AL_POSITION, posvel);
        checkErrorAndThrow(L"Failed to reset the listener's position");

        alListenerfv(AL_VELOCITY, posvel);
        checkErrorAndThrow(L"Failed to reset the listener's velocity");

        alListenerfv(AL_ORIENTATION, ori);
        checkErrorAndThrow(L"Failed to reset the listener's direction");
    }

    AudioSystem::~AudioSystem()
    {
        alutExit();
    }

    IWorld* AudioSystem::createWorld()
    {
        return new World();
    }
}}}